package com.activity;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.adapter.base.ViewHolder;
import com.adapter.base.recyclerview.CommonAdapter;
import com.util.R;
import com.view.DropDownAndPullUpLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/7/2.
 */
public class DropDownAndPullUpAcy extends BaseActivity {
    @Bind(R.id.ddpu_dropDownAndPullUpAcy)
    DropDownAndPullUpLayout ddpu;
    @Bind(R.id.rv_dropDownAndPullUpAcy)
    RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acy_dropdown_and_pullup);
        ButterKnife.bind(this);
        initData();
    }

    @Override
    protected void initData() {
        super.initData();
        List<String> dataList = new ArrayList<>();
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        dataList.add("下拉刷新上拉加载更多");
        recyclerView.setLayoutManager(new LinearLayoutManager(DropDownAndPullUpAcy.this,LinearLayoutManager.VERTICAL,false));
        recyclerView.setAdapter(new CommonAdapter<String>(DropDownAndPullUpAcy.this, R.layout.recyclerview_item_text, dataList) {
            @Override
            public void convert(ViewHolder holder, String s) {
                holder.setText(R.id.tv_item_recyclerView, s);
            }
        });
        ddpu.setLoadMoreListener(new DropDownAndPullUpLayout.LoadMoreListener() {
            @Override
            public void onLoadMore() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ddpu.onLoadMoreCompleted();
                    }
                }, 5000);
            }
        });
        ddpu.setRefreshListener(new DropDownAndPullUpLayout.RefreshListener() {
            @Override
            public void onRefreshing() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ddpu.onRefreshCompleted();
                    }
                }, 5000);
            }
        });
    }
}
